package com.scalar.chiptrack.utils;

import java.sql.Connection;
import java.sql.DriverManager;

import javax.sql.DataSource;

public final class DBLoader {
    
    public static final String DB_URL = "jdbc:microsoft:sqlserver://server:1433;DatabaseName=chiptrack";
    public static final String DB_LOGIN = "sa";
    public static final String DB_PASS = "ontrack20";
    
    private static DBLoader s_dbLoader = null;
    private DataSource m_dataSource = null;

    private DBLoader() throws Exception {
        /*System.setProperty("java.naming.factory.initial", "org.apache.naming.java.javaURLContextFactory");
        Context context = (Context) new InitialContext().lookup ("java:comp/env");
        m_dataSource = (DataSource) context.lookup ("jdbc/ontrack");*/
        System.setProperty("jdbc.drivers", "com.microsoft.jdbc.sqlserver.SQLServerDriver");
    }
	
    public static DBLoader getInstance() throws Exception {
        return new DBLoader();
    }
	
    public Connection getConnection() throws Exception {
        /*
         * IF YOU ARE RUNNING WITH IN TOMCAT
         return m_dataSource.getConnection();
         */
        Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
        Connection conn = DriverManager.getConnection (DB_URL, DB_LOGIN, DB_PASS);
        conn.setAutoCommit(false);
        return conn;
    }
}